Preloading resource dictionaries
In Kanzi you can load resource dictionaries of prefabs you use in your project before your Kanzi application shows them to users. For example, you can create a loading screen that your users see while Kanzi is loading the resource dictionaries of the rest of your application in the background. Once your application loads all the resources you select, it switches from the loading screen to the part of the application you select.
To preload resource dictionaries:
-
Create a loading screen and place it under Screen > RootPage. Your users see the content of your loading screen while Kanzi loads the resource dictionaries of your application.
For example, create and image and show it in an Image, or create a Scene which contains an animation that is shown while Kanzi is loading the resources.
- Create your Kanzi application in Prefabs and add to the scope of each prefab all the resources used by that prefab. See Using prefabs and Using local and global resources.
- In the Project select the RootPage, in the Properties click Add, and add the On Attached trigger.
- In the Properties > On Attached trigger click the drop-down menu, and select Preload Resources action.
- In the Argument Editor:
- Add to the Resource Dictionaries For Preloading property object the resource dictionaries of which you want to preload.
- If you localized your Kanzi application, set the Locale property to the locale the resources of which you want to load.
For example, if you divided your application into several parts, you can load only the resource dictionary of the part users see first, and when that loads you can start loading the rest of the application. To load the resources of your entire Kanzi application at once, including all localized resources, select Screen.
- In the Project select the Screen, in the Triggers click , and add On Preloading of Resources Completed trigger.
- In the Triggers click the drop-down menu for the On Preloading of Resources Completed trigger, and select Execute Script action.
- In the Execute Script window select <Add new script...> to create a new script.
The Script Editor window opens.
- Write and save this script that Kanzi executed when the preloading of resources is completed:
// Find the RootPage object that is the parent of the Loading screen
// object you want to replace when preloading of resource is completed.
var rootPage = node.lookupNode('./RootPage');
// Find the Loading screen object you want to replace.
var loadingScreen = node.lookupNode('./RootPage/Loading screen');
// Instantiate the prefab that contains the content you want to show
// after you remove the Loading screen object.
var firstScreen = instantiatePrefab('kzb://<ProjectName>/Prefabs/Viewport 2D', 'First screen');
// Remove the Loading screen object.
rootPage.removeChild(loadingScreen);
// Add the prefab named First screen to the RootPage.
rootPage.addChild(firstScreen);
See also
Using scripts
Reference for scripting
Using local and global resources
Using external resource dictionaries
Loading resources in parallel
Resource management
Triggers
Using prefabs
Open topic with navigation